package com.kele.ref;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.io.IOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.Properties;

/**
 * @Version 2019
 * @Author:kele
 * @Date:2021/6/6
 * @Content:
 * @Description：
 */
public class RefTest {

    private static Properties properties=null;
    static {
        properties=new Properties();
        try {
            properties.load(RefTest.class.getClassLoader().getResourceAsStream("bean.properties"));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
        String bean= properties.getProperty("bean");
//        System.out.println(bean);
        Class clazz=Class.forName(bean);
        Constructor constructor = clazz.getConstructor();
//        System.out.println(constructor.newInstance());
        ApplicationContext applicationContext=new ClassPathXmlApplicationContext("spring-ioc.xml");
        Cat cat= (Cat) applicationContext.getBean("cat");
        System.out.println(cat);


    }
}
